package top.catchcat.blogs.mapper;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;
import top.catchcat.blogs.dao.userIfo.User;

@Repository
public interface UserMapper {
    @Insert("INSERT INTO user VALUES (NULL, #{account_id}, #{name}, #{avatar_url}, #{bio}, NULL, #{token}, NOW(), NOW())")
    boolean insertUser(User user);

    @Update("UPDATE user SET token = #{token}")
    boolean updateTokenUser(User user);

    @Update("UPDATE user SET token = #{token}, name = #{name}, avatar_url = #{avatar_url}, bio = #{bio}, GMT_MODIFIED = NOW()")
    boolean updateUser(User user);

    @Select("SELECT * FROM user WHERE account_id = #{id}")
    User getUserByAccountId(Long id);

    @Select("SELECT * FROM user WHERE token = #{token}")
    User getUserByToken(String token);

    @Select("SELECT * FROM user WHERE id = #{id}")
    User getUserById(String id);
}
